package com.kungfuhacking.wristbandpro.net;

import com.kungfuhacking.wristbandpro.base.bean.Basebean;
import com.kungfuhacking.wristbandpro.utils.Constant;

import io.reactivex.Observer;

/**
 * 非正常的请求数据
 * Created by Aaron on 17/4/17.
 */

public abstract class BaseNoTObserver<T extends Basebean> implements Observer<T> {

    @Override
    public void onNext(T t) {

        if (t.getCode() == Constant.ERR0R_RELOGIN)
//            onReLogin();
            onReLogin(t.getCode_msg());
        else if (t.getCode() == 0)
            onHandleSuccess(t);
        else
            onHandleError(t.getCode_msg());

    }

    @Override
    public void onError(Throwable e) {
        onHandleError("网络错误 : " + e.getMessage());
    }

    @Override
    public void onComplete() {

    }

    public abstract void onHandleSuccess(T t);

    public abstract void onHandleError(String message);

//    public abstract void onReLogin();
    public abstract void onReLogin(String message);

}
